#include <cuda.h>
#include <cstdio>
#include <climits>
#include <string>
#include <iostream>
#include "common.h"
#include <fcntl.h>
using namespace std;

int multiply(unsigned char* a, int n, unsigned char* b, int m, char* C);

void input(unsigned char*& a,unsigned char*& b, unsigned int& n, unsigned int& m) {
	scanf("%u %u\n", &n, &m);
	void *_a, *_b;
	cuCall(cuMemAllocHost(&(_a), (n + 1) * sizeof(char)), "cuMemAllocHost(a)");
	cuCall(cuMemAllocHost(&(_b), (m + 1) * sizeof(char)), "cuMemAllocHost(b)");
	a = (unsigned char*)_a;
	b = (unsigned char*)_b;
  scanf("%s %s", (char*)a, (char*)b);
  for (int i = 0; i < n; i++) a[i] = (char)a[i] - '0';
  for (int i = 0; i < m; i++) b[i] = (char)b[i] - '0';
}

int main(int argc, char *argv[]) {
	cuInit(0);

	CUdevice device;
	CUcontext context;
	CUmodule module;
	cuCall(cuDeviceGet(&device, 0), "cuDeviceGet");
	cuCall(cuCtxCreate(&context, CU_CTX_SCHED_SPIN | CU_CTX_MAP_HOST, device), "cuCtxCreate");
	unsigned char *a, *b;
	unsigned int n, m;

	input(a, b, n, m);

	void *C;
	cuCall(cuMemAllocHost(&C, (n+m+1) * sizeof(char)), "cuMemAlloc(C)");
  char *c = (char*)C;
	int k = multiply(a, n, b, m, c);
	cuCtxSynchronize();
	c[k] = 0;
	printf("%s", c);
	printf("\n");

	cuCtxDestroy(context);
	return 0;
}
